package com.clue.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.clue.pojo.Clue;
import com.clue.pojo.R;
import com.clue.service.ClueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/clues")
@RefreshScope
public class CLueController {

    @Value("${server.port}")
    private int port;
    @Value("${email}")
    private String email;
    @Value("${text}")
    private String text;

    @Resource
    private ClueService clueService;


    @PostMapping("/list")
    @SentinelResource(value = "clueList", blockHandler = "handlerBlock")
    public R select(){
            System.out.println("port:"+port+",email:"+email+",text:"+text);
        return R.ok(clueService.selectClueList());
    }

    public R handlerBlock(BlockException ex) {
        return R.err(503, "限流了");
    }
}
